<template>
  <div id="necessaryEdit">
    <div id="edit1" v-show="substep===1">
      <el-form ref="editForm1" :model="editForm1" label-width="150px" :rules="editForm1Rules">
        <el-form-item label="审核人" prop="verifyUserName"  style="float:left">
          <el-input type="text" v-model="editForm1.verifyUserName"></el-input>
        </el-form-item>
        <el-form-item label="审核时间" prop="verifyTime" style="float:left">
          <el-date-picker v-model="editForm1.verifyTime" type="date" placeholder="选择日期" value-format="yyyy-MM-dd"></el-date-picker>
        </el-form-item>
        <el-form-item label="是否存在问题" prop="hasProblem" style="clear:both;float:left">
          <el-radio-group v-model="editForm1.hasProblem">
            <el-radio :label="1">是</el-radio>
            <el-radio :label="0">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="存在问题" prop="problemComment" style="float:left" v-show="editForm1.hasProblem===1">
          <el-input type="text" v-model="editForm1.problemComment" style="width:600px;"></el-input>
        </el-form-item>
        <el-form-item label="附件" prop="file1" style="clear:both;">
          <el-upload
            class="upload-demo"
            :action="this.$http.defaults.baseURL + this.$http.defaults.selectionAPI + 'api/gen/file/upload/'"
            :on-remove="handleRemove"
            :before-remove="beforeRemove"
            multiple
            :on-success="getImportList1"
            :file-list="fileList1"
            :on-error='uploaderror'
            with-credentials>
            <el-button type="primary">点击上传</el-button>
          </el-upload>
        </el-form-item>
        <el-form-item label="办理提示" prop="opinion" style="float:left">
          <el-autocomplete :trigger-on-focus="false" :fetch-suggestions="querySearch" v-model="editForm1.opinion" style="width:600px" :maxlength="200"></el-autocomplete>
          <!-- <el-popover
            placement="top"
            width="300"
            trigger="click"
            v-model="visible">
            <div class="pop-item" v-for="(item, idx) of yyData" :key="idx" @click="editForm1.opinion = item ; visible = !visible">{{item}}</div>
            <el-button type="primary" slot="reference" v-show="yyData&&yyData.length>0">常用用语库</el-button>
          </el-popover> -->
        </el-form-item>
        <el-form-item style="clear:both;">
        <el-button @click="saveitem(1,false)" :loading="loading">暂存</el-button>
        <el-button type="success" @click="saveitem(1,true)" :loading="loading">保存并报给监督处处长</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div id="edit2" v-show="substep===2">
      <el-form ref="editForm2" :model="editForm2" label-width="150px" :rules="editForm2Rules">
        <el-form-item label="审核人" prop="verifyUserName"  style="float:left">
          <el-input type="text" v-model="editForm2.verifyUserName"></el-input>
        </el-form-item>
        <el-form-item label="审核时间" prop="verifyTime" style="float:left">
          <el-date-picker v-model="editForm2.verifyTime" type="date" placeholder="选择日期" value-format="yyyy-MM-dd"></el-date-picker>
        </el-form-item>
        <el-form-item label="认定结果" prop="confirmResult" style="clear:both;">
          <el-radio-group v-model="editForm2.confirmResult">
            <el-radio :label="1">基本一致</el-radio>
            <el-radio :label="2">漏报较轻</el-radio>
            <el-radio :label="3">漏报较重</el-radio>
            <el-radio :label="4">瞒报</el-radio>
            <el-radio :label="5">存在其他违法违纪</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否存在问题" prop="hasProblem" style="clear:both;float:left">
          <el-radio-group v-model="editForm2.hasProblem">
            <el-radio :label="1">是</el-radio>
            <el-radio :label="0">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="存在问题" prop="problemComment" style="float:left" v-show="editForm2.hasProblem===1">
          <el-input type="text" v-model="editForm2.problemComment" style="width:800px;"></el-input>
        </el-form-item>
        <el-form-item label="附件" prop="file" style="clear:both;">
          <el-upload
            class="upload-demo"
            :action="this.$http.defaults.baseURL + this.$http.defaults.selectionAPI + 'api/gen/file/upload/'"
            :on-remove="handleRemove"
            :before-remove="beforeRemove"
            multiple
            :on-success="getImportList2"
            :file-list="fileList2"
            :on-error='uploaderror'
            with-credentials>
            <el-button type="primary">点击上传</el-button>
          </el-upload>
        </el-form-item>
        <el-form-item label="办理提示" prop="opinion" style="float:left">
          <el-autocomplete :trigger-on-focus="false" :fetch-suggestions="querySearch" v-model="editForm2.opinion" style="width:600px" :maxlength="200"></el-autocomplete>
          <!-- <el-popover
            placement="top"
            width="300"
            trigger="click"
            v-model="visible">
            <div class="pop-item" v-for="(item, idx) of yyData" :key="idx" @click="editForm2.opinion = item ; visible = !visible">{{item}}</div>
            <el-button type="primary" slot="reference" v-show="yyData&&yyData.length>0">常用用语库</el-button>
          </el-popover> -->
        </el-form-item>
        <el-form-item style="clear:both;">
        <el-button @click="saveitem(2,false)" :loading="loading">暂存</el-button>
        <el-button type="success" @click="saveitem(2,true)" :loading="loading">保存并报给监督处处长</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div id="edit3" v-show="substep===3">
      <el-form ref="editForm3" :model="editForm3" label-width="150px" :rules="editForm3Rules">
        <el-checkbox label="需要征求驻部纪检监察组意见" v-model="zbjjzflag"></el-checkbox>
        <fieldset v-show="zbjjzflag">
          <legend>征求驻部纪检监察组意见</legend>
          <el-form-item label="征求时间" prop="askingTime" style="float:left">
            <el-date-picker v-model="editForm3.askingTime" type="date" placeholder="选择日期" value-format="yyyy-MM-dd"></el-date-picker>
          </el-form-item>
          <el-form-item label="反馈时间" prop="feedbackTime" style="float:left">
            <el-date-picker v-model="editForm3.feedbackTime" type="date" placeholder="选择日期" value-format="yyyy-MM-dd"></el-date-picker>
          </el-form-item>
          <el-form-item label="反馈意见" prop="feedbackOpinion" style="clear:both;">
            <el-input type="text" v-model="editForm3.feedbackOpinion" style="width:800px;"></el-input>
          </el-form-item>
          <el-form-item label="是否存在问题" prop="hasProblem" style="clear:both;float:left">
            <el-radio-group v-model="editForm3.hasProblem">
              <el-radio :label="1">是</el-radio>
              <el-radio :label="0">否</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="存在问题" prop="problemComment" style="float:left" v-show="editForm3.hasProblem===1">
            <el-input type="text" v-model="editForm3.problemComment" style="width:800px;"></el-input>
          </el-form-item>
          <el-form-item label="附件" prop="file" style="clear:both;">
            <el-upload
              class="upload-demo"
              :action="this.$http.defaults.baseURL + this.$http.defaults.selectionAPI + 'api/gen/file/upload/'"
              :on-remove="handleRemove"
              :before-remove="beforeRemove"
              multiple
              :on-success="getImportList3"
              :file-list="fileList3"
              :on-error='uploaderror'
              with-credentials>
              <el-button type="primary">点击上传</el-button>
            </el-upload>
          </el-form-item>
        </fieldset>
        <!-- <el-form-item label="办理提示" prop="opinion" style="float:left">
          <el-autocomplete :trigger-on-focus="false" :fetch-suggestions="querySearch" v-model="editForm3.opinion" style="width:600px" :maxlength="200"></el-autocomplete>
          <el-popover
            placement="top"
            width="300"
            trigger="click"
            v-model="visible">
            <div class="pop-item" v-for="(item, idx) of yyData" :key="idx" @click="editForm3.opinion = item ; visible = !visible">{{item}}</div>
            <el-button type="primary" slot="reference" v-show="yyData&&yyData.length>0">常用用语库</el-button>
          </el-popover>
        </el-form-item> -->
        <div style="clear:both;margin-top:20px;"></div>
        <el-checkbox label="需要征求机关纪委意见" v-model="jgjwflag"></el-checkbox>
        <fieldset v-show="jgjwflag">
          <legend>征求机关纪委意见</legend>
          <el-form-item label="征求时间" prop="askingTime2" style="float:left">
            <el-date-picker v-model="editForm3.askingTime2" type="date" placeholder="选择日期" value-format="yyyy-MM-dd"></el-date-picker>
          </el-form-item>
          <el-form-item label="反馈时间" prop="feedbackTime2" style="float:left">
            <el-date-picker v-model="editForm3.feedbackTime2" type="date" placeholder="选择日期" value-format="yyyy-MM-dd"></el-date-picker>
          </el-form-item>
          <el-form-item label="反馈意见" prop="feedbackOpinion2" style="clear:both;">
            <el-input type="text" v-model="editForm3.feedbackOpinion2" style="width:800px;"></el-input>
          </el-form-item>
          <el-form-item label="是否存在问题" prop="hasProblem2" style="clear:both;float:left">
            <el-radio-group v-model="editForm3.hasProblem2">
              <el-radio :label="1">是</el-radio>
              <el-radio :label="0">否</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="存在问题" prop="problemComment2" style="float:left" v-show="editForm3.hasProblem2===1">
            <el-input type="text" v-model="editForm3.problemComment2" style="width:800px;"></el-input>
          </el-form-item>
          <el-form-item label="附件" prop="file" style="clear:both;">
            <el-upload
              class="upload-demo"
              :action="this.$http.defaults.baseURL + this.$http.defaults.selectionAPI + 'api/gen/file/upload/'"
              :on-remove="handleRemove"
              :before-remove="beforeRemove"
              multiple
              :on-success="getImportList3b"
              :file-list="fileList3b"
              :on-error='uploaderror'
              with-credentials>
              <el-button type="primary">点击上传</el-button>
            </el-upload>
          </el-form-item>
        </fieldset>
        <div style="clear:both"></div>
        <el-form-item label="办理提示" prop="opinion" style="float:left;margin-top:10px;clear:both">
          <el-autocomplete :trigger-on-focus="false" :fetch-suggestions="querySearch" v-model="editForm3.opinion" style="width:600px" :maxlength="200"></el-autocomplete>
          <!-- <el-popover
            placement="top"
            width="300"
            trigger="click"
            v-model="visible">
            <div class="pop-item" v-for="(item, idx) of yyData" :key="idx" @click="editForm3.opinion = item ; visible = !visible">{{item}}</div>
            <el-button type="primary" slot="reference" v-show="yyData&&yyData.length>0">常用用语库</el-button>
          </el-popover> -->
        </el-form-item>
        <div style="clear:both;margin-top:20px;margin-left:150px">
          <el-button @click="saveitem(3,false)" :loading="loading">暂存</el-button>
          <el-button type="success" @click="saveitem(3,true)" :loading="loading1">保存并报给监督处处长</el-button>
        </div>
      </el-form>
      <!-- <span style="color:red;font-weight:bolder;margin-left:150px;">注：征求驻部纪检监察组意见和征求机关纪委意见都保存后自动报给监督处处长</span> -->
    </div>
    <div id="edit4" v-show="substep===4">
      <el-form ref="editForm4" :model="editForm4" label-width="150px" :rules="editForm4Rules">
        <el-form-item label="是否有可查性线索举报" prop="hasTraceableClues" style="clear:both" label-width="200px">
          <el-radio-group v-model="editForm4.hasTraceableClues">
            <el-radio :label="1">是</el-radio>
            <el-radio :label="0">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="调查核实情况" prop="verifySituation" style="clear:both" v-show="editForm4.hasTraceableClues===1">
          <el-input type="textarea" v-model="editForm4.verifySituation" style="width:800px;"></el-input>
        </el-form-item>
        <el-form-item label="附件" prop="file" style="clear:both;">
          <el-upload
            class="upload-demo"
            :action="this.$http.defaults.baseURL + this.$http.defaults.selectionAPI + 'api/gen/file/upload/'"
            :on-remove="handleRemove"
            :before-remove="beforeRemove"
            multiple
            :on-success="getImportList4"
            :file-list="fileList4"
            :on-error='uploaderror'
            with-credentials>
            <el-button type="primary">点击上传</el-button>
          </el-upload>
        </el-form-item>
        <el-form-item label="办理提示" prop="opinion" style="float:left">
          <el-autocomplete :trigger-on-focus="false" :fetch-suggestions="querySearch" v-model="editForm4.opinion" style="width:600px" :maxlength="200"></el-autocomplete>
          <!-- <el-popover
            placement="top"
            width="300"
            trigger="click"
            v-model="visible">
            <div class="pop-item" v-for="(item, idx) of yyData" :key="idx" @click="editForm4.opinion = item ; visible = !visible">{{item}}</div>
            <el-button type="primary" slot="reference" v-show="yyData&&yyData.length>0">常用用语库</el-button>
          </el-popover> -->
        </el-form-item>
        <el-form-item style="clear:both;">
          <el-button @click="saveitem(4,false)" :loading="loading">暂存</el-button>
          <el-button type="success" @click="saveitem(4,true)" :loading="loading">保存并报给监督处处长</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
export default {
  props: ['substep', 'personid'],
  watch: {
    substep (val, oldVal) {
      console.log('substep has changed', val)
      this.resetAllForm()
      this.getItem()
      this.$http
        .get(this.$http.defaults.selectionAPI + `api/selection/home/getCommonlyOpinions?step=` + (20 + val))
        .then(response => {
          if (response.data.success) {
            this.yyData = response.data.result
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          console.log(error)
          this.$message({
            message: '获取失败:' + error,
            type: 'error'
          })
        })
    },
    personid (val, oldVal) {
      console.log('personid has changed', val)
      this.resetAllForm()
      this.getItem()
    }
  },
  data () {
    return {
      zbjjzflag: true,
      jgjwflag: true,
      visible: false,
      yyData: [],
      loading: false,
      loading1: false,
      loading2: false,
      username: '',
      editForm1: {
        verifyUserName: '',
        verifyTime: '',
        hasProblem: 0,
        problemComment: '',
        opinion: ''
      },
      editForm1Rules: {
        verifyUserName: [{ required: true, message: '请输入审核人', trigger: 'blur' }],
        verifyTime: [{ required: true, message: '请输入审核时间', trigger: 'blur' }],
        hasProblem: [{ required: true, message: '请选择是否存在问题', trigger: 'blur' }]
      },
      fileList1: [],
      files1: [],
      editForm2: {
        verifyUserName: '',
        verifyTime: '',
        confirmResult: '',
        hasProblem: 0,
        problemComment: '',
        opinion: ''
      },
      editForm2Rules: {
        verifyUserName: [{ required: true, message: '请输入审核人', trigger: 'blur' }],
        verifyTime: [{ required: true, message: '请输入审核时间', trigger: 'blur' }],
        confirmResult: [{ required: true, message: '请选择认定结果', trigger: 'blur' }],
        hasProblem: [{ required: true, message: '请选择是否存在问题', trigger: 'blur' }]
      },
      fileList2: [],
      files2: [],
      editForm3: {
        askingTime: '',
        feedbackTime: '',
        feedbackOpinion: '',
        hasProblem: 0,
        problemComment: '',
        askingTime2: '',
        feedbackTime2: '',
        feedbackOpinion2: '',
        hasProblem2: 0,
        problemComment2: '',
        opinion: ''
      },
      editForm3Rules: {
        // askingTime: [{ required: true, message: '请输入征求时间', trigger: 'blur' }],
        // feedbackTime: [{ required: true, message: '请输入反馈时间', trigger: 'blur' }],
        // feedbackOpinion: [{ required: true, message: '请输入反馈意见', trigger: 'blur' }],
        // hasProblem: [{ required: true, message: '请选择是否存在问题', trigger: 'blur' }],
        // askingTime2: [{ required: true, message: '请输入征求时间', trigger: 'blur' }],
        // feedbackTime2: [{ required: true, message: '请输入反馈时间', trigger: 'blur' }],
        // feedbackOpinion2: [{ required: true, message: '请输入反馈意见', trigger: 'blur' }],
        // hasProblem2: [{ required: true, message: '请选择是否存在问题', trigger: 'blur' }]
      },
      fileList3: [],
      files3: [],
      fileList3b: [],
      files3b: [],
      editForm4: {
        hasTraceableClues: 0,
        verifySituation: '',
        opinion: ''
      },
      editForm4Rules: {
        hasTraceableClues: [{ required: true, message: '请选择是否有可查性线索举报', trigger: 'blur' }]
      },
      fileList4: [],
      files4: []
    }
  },
  methods: {
    querySearch (queryString, cb) {
      return this.getNotice(this, queryString, cb)
    },
    getNotice (self, queryString, cb) {
      let para = {
        key: queryString
      }
      self.$http
        .post(this.$http.defaults.selectionAPI + `api/selection/home/getMatchedOpinions`, para)
        .then(function (response) {
          console.log('获取成功')
          var results = response.data.result
          let newArr = []
          results.forEach(function (item) {
            let obj = {'value': item}
            newArr.push(obj)
          })
          cb(newArr)
        })
        .catch(function (error) {
          console.log(error)
        })
    },
    resetAllForm () {
      this.$refs['editForm1'].resetFields()
      this.$refs['editForm2'].resetFields()
      this.$refs['editForm3'].resetFields()
      this.$refs['editForm4'].resetFields()
      this.fileList1 = []
      this.files1 = []
      this.fileList2 = []
      this.files2 = []
      this.fileList3 = []
      this.files3 = []
      this.fileList3b = []
      this.files3b = []
      this.fileList4 = []
      this.files4 = []
      this.zbjjzflag = true
      this.jgjwflag = true
    },
    handleRemove (file, fileList) {
      console.log('delfileid:')
      console.log(file.id)
      let fid = file.response.result[0].id
      this.$http
        .get(this.$http.defaults.selectionAPI + `api/gen/file/remove?id=` + fid)
        .then(response => {
          if (response.data.success) {
            this.$message({
              message: '删除成功',
              type: 'success'
            })
          } else {
            this.$message({
              message: '删除失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          this.$message({
            message: '网络删除失败:' + error,
            type: 'error'
          })
        })
      // let newfiles = []
      // if (this.files && this.files.length > 0) {
      //   for (let i = 0; i < this.files.length; i++) {
      //     if (this.files[i].fileName + '.' + this.files[i].fileType !== file.name) {
      //       newfiles.push(this.files[i])
      //     }
      //   }
      // }
      // this.files = newfiles
    },
    beforeRemove (file, fileList) {
      return this.$confirm(`确定移除 ${file.name}？`)
    },
    getImportList1 (res, file, fileList) {
      if (res.success) {
        this.$message({
          message: '上传成功！' + res.message,
          type: 'success'
        })
        this.files1.push(res.result[0])
      } else {
        console.log(res.message)
        this.$message({
          message: '上传失败:' + res.message,
          type: 'error'
        })
      }
    },
    getImportList2 (res, file, fileList) {
      if (res.success) {
        this.$message({
          message: '上传成功！' + res.message,
          type: 'success'
        })
        this.files2.push(res.result[0])
      } else {
        console.log(res.message)
        this.$message({
          message: '上传失败:' + res.message,
          type: 'error'
        })
      }
    },
    getImportList3 (res, file, fileList) {
      if (res.success) {
        this.$message({
          message: '上传成功！' + res.message,
          type: 'success'
        })
        this.files3.push(res.result[0])
      } else {
        console.log(res.message)
        this.$message({
          message: '上传失败:' + res.message,
          type: 'error'
        })
      }
    },
    getImportList3b (res, file, fileList) {
      if (res.success) {
        this.$message({
          message: '上传成功！' + res.message,
          type: 'success'
        })
        this.files3b.push(res.result[0])
      } else {
        console.log(res.message)
        this.$message({
          message: '上传失败:' + res.message,
          type: 'error'
        })
      }
    },
    getImportList4 (res, file, fileList) {
      if (res.success) {
        this.$message({
          message: '上传成功！' + res.message,
          type: 'success'
        })
        this.files4.push(res.result[0])
      } else {
        console.log(res.message)
        this.$message({
          message: '上传失败:' + res.message,
          type: 'error'
        })
      }
    },
    uploaderror (err) {
      console.log('具体错误')
      console.log(err)
      this.$message({
        message: '上传失败:' + err,
        type: 'error'
      })
    },
    saveitem (substep, flag) {
      let msg = ''
      if (flag) {
        msg = '保存成功并已报监督处处长'
      } else {
        msg = '暂存成功'
      }
      console.log('this.personid' + this.personid)
      if (substep === 1) {
        console.log('checkform1')
        this.$refs['editForm1'].validate((valid) => {
          if (valid || !flag) {
            console.log('this.editForm1.hasProblem')
            console.log(this.editForm1.hasProblem)
            console.log('this.editForm1.problemComment')
            console.log(this.editForm1.problemComment)
            if (this.editForm1.hasProblem && (!this.editForm1.problemComment || this.editForm1.problemComment === '')) {
              this.$message({
                message: '如存在问题请进行详细描述',
                type: 'error'
              })
            } else {
              let fileids = []
              if (this.files1 && this.files1.length > 0) {
                for (let i = 0; i < this.files1.length; i++) {
                  fileids.push(this.files1[i].id)
                }
              }
              if (this.editForm1.hasProblem === 0) { this.editForm1.problemComment = '无' }
              let para = {
                files: fileids,
                hasProblem: this.editForm1.hasProblem,
                personId: this.personid,
                problemComment: this.editForm1.problemComment,
                verifyUserName: this.editForm1.verifyUserName,
                verifyTime: this.editForm1.verifyTime,
                opinion: this.editForm1.opinion,
                completed: flag
              }
              this.loading = true
              this.$http
                .post(this.$http.defaults.selectionAPI + `api/selection/necessary/submitCadreArchives`, para)
                .then(response => {
                  if (response.data.success) {
                    this.$message({
                      message: msg,
                      type: 'success'
                    })
                    this.$emit('closedialog')
                  } else {
                    this.$message({
                      message: '提交失败:' + response.data.message,
                      type: 'error'
                    })
                  }
                  this.loading = false
                })
                .catch(error => {
                  this.$message({
                    message: '网络提交失败:' + error,
                    type: 'error'
                  })
                  this.loading = false
                })
            }
          }
        })
      }
      if (substep === 2) {
        this.$refs['editForm2'].validate((valid) => {
          if (valid || !flag) {
            if (this.editForm2.hasProblem && (!this.editForm2.problemComment || this.editForm2.problemComment === '')) {
              this.$message({
                message: '如存在问题请进行详细描述',
                type: 'error'
              })
            } else {
              let fileids = []
              if (this.files2 && this.files2.length > 0) {
                for (let i = 0; i < this.files2.length; i++) {
                  fileids.push(this.files2[i].id)
                }
              }
              if (this.editForm2.hasProblem === 0) { this.editForm2.problemComment = '无' }
              let para = {
                files: fileids,
                hasProblem: this.editForm2.hasProblem,
                personId: this.personid,
                confirmResult: this.editForm2.confirmResult,
                problemComment: this.editForm2.problemComment,
                verifyUserName: this.editForm2.verifyUserName,
                verifyTime: this.editForm2.verifyTime,
                opinion: this.editForm2.opinion,
                completed: flag
              }
              this.loading = true
              this.$http
                .post(this.$http.defaults.selectionAPI + `api/selection/necessary/submitPersonalMatters`, para)
                .then(response => {
                  if (response.data.success) {
                    this.$message({
                      message: msg,
                      type: 'success'
                    })
                    this.$emit('closedialog')
                  } else {
                    this.$message({
                      message: '提交失败:' + response.data.message,
                      type: 'error'
                    })
                  }
                  this.loading = false
                })
                .catch(error => {
                  this.$message({
                    message: '网络提交失败:' + error,
                    type: 'error'
                  })
                  this.loading = false
                })
            }
          }
        })
      }
      if (substep === 3) {
        if (!this.jgjwflag && !this.zbjjzflag) {
          this.$message({
            message: '征求驻部纪检监察组意见、征求机关纪委意见至少选择一项',
            type: 'error'
          })
        } else {
          this.$refs['editForm3'].validate((valid) => {
            if (valid || !flag) {
              if (this.editForm3.hasProblem && (!this.editForm3.problemComment || this.editForm3.problemComment === '')) {
                this.$message({
                  message: '如存在问题请进行详细描述',
                  type: 'error'
                })
              } else {
                let fileids = []
                if (this.files3 && this.files3.length > 0) {
                  for (let i = 0; i < this.files3.length; i++) {
                    fileids.push(this.files3[i].id)
                  }
                }
                if (this.editForm3.hasProblem === 0) { this.editForm3.problemComment = '无' }

                let fileids2 = []
                if (this.files3b && this.files3b.length > 0) {
                  for (let i = 0; i < this.files3b.length; i++) {
                    fileids2.push(this.files3b[i].id)
                  }
                }
                if (this.editForm3.hasProblem2 === 0) { this.editForm3.problemComment2 = '无' }
                let para = {
                  personId: this.personid,
                  opinion: this.editForm3.opinion,
                  completed: flag,
                  checkFlag: this.zbjjzflag ? 1 : 0,
                  checkFlag2: this.jgjwflag ? 1 : 0,
                  files1: fileids,
                  files2: fileids2,
                  hasProblem: this.editForm3.hasProblem,
                  hasProblem2: this.editForm3.hasProblem2,
                  problemComment: this.editForm3.problemComment,
                  problemComment2: this.editForm3.problemComment2,
                  askingTime: this.editForm3.askingTime,
                  askingTime2: this.editForm3.askingTime2,
                  feedbackTime: this.editForm3.feedbackTime,
                  feedbackTime2: this.editForm3.feedbackTime2,
                  feedbackOpinion: this.editForm3.feedbackOpinion,
                  feedbackOpinion2: this.editForm3.feedbackOpinion2
                }
                this.loading1 = true
                this.$http
                  .post(this.$http.defaults.selectionAPI + `api/selection/necessary/submitSolicitingOpinions`, para)
                  .then(response => {
                    if (response.data.success) {
                      this.$message({
                        message: msg,
                        type: 'success'
                      })
                      this.$emit('closedialog')
                    } else {
                      this.$message({
                        message: '提交失败:' + response.data.message,
                        type: 'error'
                      })
                    }
                    this.loading1 = false
                  })
                  .catch(error => {
                    this.$message({
                      message: '网络提交失败:' + error,
                      type: 'error'
                    })
                    this.loading1 = false
                  })
              }
            }
          })
        }
      }
      if (substep === 4) {
        this.$refs['editForm4'].validate((valid) => {
          if (valid || !flag) {
            if (this.editForm4.hasTraceableClues && this.editForm4.verifySituation === '') {
              this.$message({
                message: '如有可查性线索举报，请填写调查核实情况',
                type: 'error'
              })
            } else {
              let fileids = []
              if (this.files4 && this.files4.length > 0) {
                for (let i = 0; i < this.files4.length; i++) {
                  fileids.push(this.files4[i].id)
                }
              }
              if (this.editForm4.hasTraceableClues === 0) { this.editForm4.verifySituation = '无' }
              let para = {
                files: fileids,
                hasTraceableClues: this.editForm4.hasTraceableClues,
                personId: this.personid,
                verifySituation: this.editForm4.verifySituation,
                opinion: this.editForm4.opinion,
                completed: flag
              }
              this.loading = true
              this.$http
                .post(this.$http.defaults.selectionAPI + `api/selection/necessary/submitClueReporting`, para)
                .then(response => {
                  if (response.data.success) {
                    this.$message({
                      message: msg,
                      type: 'success'
                    })
                    this.$emit('closedialog')
                  } else {
                    this.$message({
                      message: '提交失败:' + response.data.message,
                      type: 'error'
                    })
                  }
                  this.loading = false
                })
                .catch(error => {
                  this.$message({
                    message: '网络提交失败:' + error,
                    type: 'error'
                  })
                  this.loading = false
                })
            }
          }
        })
      }
    },
    getItem () {
      this.pageloading = true
      this.editForm1.verifyTime = ''
      this.editForm1.hasProblem = ''
      this.editForm1.problemComment = ''
      this.fileList1 = []
      this.editForm2.verifyTime = ''
      this.editForm2.confirmResult = ''
      this.editForm2.hasProblem = ''
      this.editForm2.problemComment = ''
      this.fileList2 = []
      this.editForm3.askingTime = ''
      this.editForm3.feedbackTime = ''
      this.editForm3.askingTime2 = ''
      this.editForm3.feedbackTime2 = ''
      this.editForm3.feedbackOpinion = ''
      this.editForm3.feedbackOpinion2 = ''
      this.editForm3.hasProblem = ''
      this.editForm3.hasProblem2 = ''
      this.editForm3.problemComment = ''
      this.editForm3.problemComment2 = ''
      this.fileList3 = []
      this.fileList3b = []
      this.editForm4.hasTraceableClues = ''
      this.editForm4.verifySituation = ''
      this.editForm1.verifyUserName = ''
      this.editForm2.verifyUserName = ''
      this.fileList4 = []
      if (this.personid) {
        let para = {
          personId: this.personid
        }
        this.$http
          .post(this.$http.defaults.selectionAPI + `api/selection/necessary/getPersonStepInfo`, para)
          .then(response => {
            if (response.data.success) {
            // 获取分项信息后具体处理
              this.pageloading = false
              if (response.data.result.cadreArchivesVerifyTime) {
                let mydate1 = response.data.result.cadreArchivesVerifyTime
                this.editForm1.verifyTime = mydate1
              }
              if (!response.data.result.cadreArchivesVerifyUserName || response.data.result.cadreArchivesVerifyUserName === '') {
                this.editForm1.verifyUserName = localStorage.getItem('userTrueName')
              } else {
                this.editForm1.verifyUserName = response.data.result.cadreArchivesVerifyUserName
              }
              if (response.data.result.cadreArchivesHasProblem || response.data.result.cadreArchivesHasProblem === 0) {
                this.editForm1.hasProblem = response.data.result.cadreArchivesHasProblem
              }
              this.editForm1.problemComment = response.data.result.cadreArchivesProblemComment
              this.fileList1 = this.formatFiles(response.data.result.cadreArchivesFiles)
              if (response.data.result.personalMattersVerifyTime) {
                let mydate2 = response.data.result.personalMattersVerifyTime
                this.editForm2.verifyTime = mydate2
              }
              if (!response.data.result.personalMattersVerifyUserName || response.data.result.personalMattersVerifyUserName === '') {
                this.editForm2.verifyUserName = localStorage.getItem('userTrueName')
              } else {
                this.editForm2.verifyUserName = response.data.result.personalMattersVerifyUserName
              }
              this.editForm2.confirmResult = response.data.result.personalMattersConfirmResult
              if (response.data.result.personalMattersHasProblem || response.data.result.personalMattersHasProblem === 0) {
                this.editForm2.hasProblem = response.data.result.personalMattersHasProblem
              }
              this.editForm2.problemComment = response.data.result.personalMattersProblemComment
              this.fileList2 = this.formatFiles(response.data.result.personalMattersFiles)
              if (response.data.result.solicitingOpinionsAskingTime) {
                let mydate31 = response.data.result.solicitingOpinionsAskingTime
                this.editForm3.askingTime = mydate31
              }
              if (response.data.result.solicitingOpinionsFeedbackTime) {
                let mydate32 = response.data.result.solicitingOpinionsFeedbackTime
                this.editForm3.feedbackTime = mydate32
              }
              if (response.data.result.solicitingOpinionsAskingTime2) {
                let mydate31b = response.data.result.solicitingOpinionsAskingTime2
                this.editForm3.askingTime2 = mydate31b
              }
              if (response.data.result.solicitingOpinionsFeedbackTime2) {
                let mydate32b = response.data.result.solicitingOpinionsFeedbackTime2
                this.editForm3.feedbackTime2 = mydate32b
              }
              this.editForm3.feedbackOpinion = response.data.result.solicitingOpinionsFeedbackOpinion
              this.editForm3.feedbackOpinion2 = response.data.result.solicitingOpinionsFeedbackOpinion2
              if (response.data.result.solicitingOpinionsHasProblem || response.data.result.solicitingOpinionsHasProblem === 0) {
                this.editForm3.hasProblem = response.data.result.solicitingOpinionsHasProblem
              }
              if (response.data.result.solicitingOpinionsHasProblem2 || response.data.result.solicitingOpinionsHasProblem2 === 0) {
                this.editForm3.hasProblem2 = response.data.result.solicitingOpinionsHasProblem2
              }
              this.editForm3.problemComment = response.data.result.solicitingOpinionsProblemComment
              this.editForm3.problemComment2 = response.data.result.solicitingOpinionsProblemComment2
              this.fileList3 = this.formatFiles(response.data.result.solicitingOpinionsFiles1)
              this.fileList3b = this.formatFiles(response.data.result.solicitingOpinionsFiles2)
              this.editForm4.hasTraceableClues = response.data.result.clueReportingHasTraceableClues
              if (response.data.result.clueReportingVerifySituation || response.data.result.clueReportingVerifySituation === 0) {
                this.editForm4.verifySituation = response.data.result.clueReportingVerifySituation
              }
              this.fileList4 = this.formatFiles(response.data.result.clueReportingFiles)
              if (response.data.result.checkFlag === 0) {
                this.zbjjzflag = false
              }
              if (response.data.result.checkFlag === 1) {
                this.zbjjzflag = true
              }
              if (response.data.result.checkFlag2 === 0) {
                this.jgjwflag = false
              }
              if (response.data.result.checkFlag2 === 1) {
                this.jgjwflag = true
              }
            } else {
              this.$message({
                message: '获取失败:' + response.data.message,
                type: 'error'
              })
            }
          })
          .catch(error => {
            this.$message({
              message: '网络获取失败:' + error,
              type: 'error'
            })
            this.FormLoading = false
          })
      }
    },
    formatFiles (files) {
      if (files && files.length > 0) {
        let newfiles = []
        for (let i = 0; i < files.length; i++) {
          newfiles.push({name: files[i].fileName + '.' + files[i].fileType, id: files[i].id})
        }
        return newfiles
      }
    }
  },
  mounted () {
    this.getItem()
  }
}
</script>
